package thread;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: hmm
 * @Created: 2019/11/5
 * @Description:
 * @Modified by:
 */
public class Demo5 {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(10, 10, 30, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        poolExecutor.execute(() -> {
            excute();
        });
        poolExecutor.execute(() -> {
            excute();
        });

        poolExecutor.shutdown();
    }

    private static void excute() {
        lock.lock();
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "============" + i);
        }
        lock.unlock();
    }
}
